from tortoise import fields, models


class UserModel(models.Model):
    """后台管理系统用户模型"""
    
    id = fields.IntField(pk=True)
    username = fields.CharField(max_length=50, unique=True, description="用户名")
    password = fields.CharField(max_length=128, description="密码")
    nickname = fields.CharField(max_length=50, null=True, description="昵称")
    avatar = fields.CharField(max_length=255, null=True, description="头像")
    email = fields.CharField(max_length=255, null=True, description="邮箱")
    phone = fields.CharField(max_length=20, null=True, description="手机号")
    role_id = fields.IntField(default=0, description="角色ID")
    dept_id = fields.IntField(default=0, description="部门ID")
    position = fields.CharField(max_length=50, null=True, description="职位")
    is_active = fields.BooleanField(default=True, description="是否激活")
    is_superuser = fields.BooleanField(default=False, description="是否超级管理员")
    last_login = fields.DatetimeField(null=True, description="最后登录时间")
    last_ip = fields.CharField(max_length=50, null=True, description="最后登录IP")
    remark = fields.TextField(null=True, description="备注")
    created_at = fields.DatetimeField(auto_now_add=True, description="创建时间")
    updated_at = fields.DatetimeField(auto_now=True, description="更新时间")

    class Meta:
        """模型元数据
        
        - table: 指定数据库表名
        - table_description: 表描述，用于数据库文档
        """
        table = "users"
        table_description = "后台管理系统用户表"

    def __str__(self):
        """返回用户的字符串表示，用于调试和显示"""
        return self.username